/*
 * @Author: Leo
 * @Date: 2021-12-08 11:40:44
 * @LastEditors: Leo
 * @LastEditTime: 2021-12-09 18:06:26
 * @Description: file content
 */
let settings = {
  isEnabled: true,
}
console.log(`${66666  }background bg`);
// default settings for development environment
if (process.env.NODE_ENV === 'development') {
  settings = {
    isEnabled: true,
  }

  console.info('Extension initialized with settings: ', settings)
}

function loadSettings() {
  chrome.storage.sync.get((items) => {
    if (items.settings) settings = items.settings
  })
}

function saveSettings(updated) {
  if (updated) settings = updated

  chrome.storage.sync.set({
    settings,
  })
}



// 监听来自content-script的消息
chrome.runtime.onMessage.addListener((message) => {
  if (!settings.isEnabled) return

  console.log(message, settings)
})

chrome.runtime.onInstalled.addListener(() => {
  saveSettings()
})

loadSettings()
